import * as path from "path";
import { HttpServer } from "tsrpc";
import { Global } from "./models/Global";
import { serviceProto } from "./shared/protocols/serviceProto";

// Create the Server
// const server = new HttpServer(serviceProto, {
//     port: 3000,
//     cors: '*',
// });

// // Entry function
// async function main() {
//     // Auto implement APIs
//     await server.autoImplementApi(path.resolve(__dirname, 'api'));

//     await Global.init(server.logger);

//     await server.start();
// };

// main().catch(e => {
//     // Exit if any error during the startup
//     server.logger.error(e);
//     process.exit(-1);
// });
const server = new HttpServer(serviceProto, {
    port: 3000,
    json: true
});


// Initialize before server start
async function init() {
    await server.autoImplementApi(path.resolve(__dirname, 'api'));
    await Global.initDb();
};

// Entry function
async function main() {
    await init();
    await server.start();
};
main();